#!/usr/bin/python
#Derek & Paddy
import unittest
from ChessBoard import *

class testState2str(unittest.TestCase):

  def setUp(self):
    """ 
    SetUp data used for tests
    """
    self.testBoard = ChessBoard()
    self.testBoard.resetBoard()
   
  def testInit(self):
    """
    Test is not none 
    """
    self.assertTrue(self.testBoard is not None)

  def testBasic(self):
    """
    """
    a = self.testBoard.state2str()
    print a

  def testMovePiece(self):
    """
    """
    a = self.testBoard.state2str()
    self.testBoard.movePawn((1,6),(1,5))

    b = self.testBoard.state2str()
    #print a
    #print b
    #for i in range(len(b)):
      #print b[i] + " - " + str(i)

    self.assertTrue(a != b)
    self.assertEqual(a[0:40], b[0:40])
    self.assertEqual('P', b[41])
    self.assertEqual(a[42:48], b[42:48])
    self.assertEqual('.', b[49])
    self.assertEqual(a[50:], b[50:])

  def testChangeFlagWhiteKingCastle(self):
    """
    """
    self.assertTrue(self.testBoard._white_king_castle)
    self.testBoard._white_king_castle = False
    self.assertFlagValue(0, -9)

  def testChangeFlagWhiteQueenCastle(self):
    """
    """
    self.assertTrue(self.testBoard._white_queen_castle)
    self.testBoard._white_queen_castle = False
    self.assertFlagValue(0, -8)
    

  def assertFlagValue(self, expected, position):
    val = self.testBoard.state2str()
    self.assertEqual(str(expected), val[position])

if __name__ == "__main__":
  unittest.main()

